﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.DrawingSettings
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Settings for ScriptableRenderContext.DrawRenderers.</para>
  /// </summary>
  public struct DrawingSettings : IEquatable<DrawingSettings>
  {
    private const int kMaxShaderPasses = 16;
    /// <summary>
    ///   <para>The maxiumum number of passes that can be rendered in 1 DrawRenderers call.</para>
    /// </summary>
    public static readonly int maxShaderPasses = 16;
    private SortingSettings m_SortingSettings;
    internal unsafe fixed int shaderPassNames[16];
    private PerObjectData m_PerObjectData;
    private DrawRendererFlags m_Flags;
    private int m_OverrideMaterialInstanceId;
    private int m_OverrideMaterialPassIndex;
    private int m_fallbackMaterialInstanceId;
    private int m_MainLightIndex;
    private int m_UseSrpBatcher;

    /// <summary>
    ///   <para>Create a draw settings struct.</para>
    /// </summary>
    /// <param name="shaderPassName">Shader pass to use.</param>
    /// <param name="sortingSettings">Describes the methods to sort objects during rendering.</param>
    public unsafe DrawingSettings(ShaderTagId shaderPassName, SortingSettings sortingSettings)
    {
      this.m_SortingSettings = sortingSettings;
      this.m_PerObjectData = PerObjectData.None;
      this.m_Flags = DrawRendererFlags.EnableInstancing;
      this.m_OverrideMaterialInstanceId = 0;
      this.m_OverrideMaterialPassIndex = 0;
      this.m_fallbackMaterialInstanceId = 0;
      this.m_MainLightIndex = -1;
      fixed (int* numPtr = this.shaderPassNames)
      {
        numPtr[0] = shaderPassName.id;
        for (int index = 1; index < DrawingSettings.maxShaderPasses; ++index)
          numPtr[index] = -1;
      }
      this.m_PerObjectData = PerObjectData.None;
      this.m_Flags = DrawRendererFlags.EnableInstancing;
      this.m_UseSrpBatcher = 0;
    }

    /// <summary>
    ///   <para>How to sort objects during rendering.</para>
    /// </summary>
    public SortingSettings sortingSettings
    {
      get => this.m_SortingSettings;
      set => this.m_SortingSettings = value;
    }

    /// <summary>
    ///   <para>What kind of per-object data to setup during rendering.</para>
    /// </summary>
    public PerObjectData perObjectData
    {
      get => this.m_PerObjectData;
      set => this.m_PerObjectData = value;
    }

    /// <summary>
    ///   <para>Controls whether dynamic batching is enabled.</para>
    /// </summary>
    public bool enableDynamicBatching
    {
      get => (this.m_Flags & DrawRendererFlags.EnableDynamicBatching) != 0;
      set
      {
        if (value)
          this.m_Flags |= DrawRendererFlags.EnableDynamicBatching;
        else
          this.m_Flags &= ~DrawRendererFlags.EnableDynamicBatching;
      }
    }

    /// <summary>
    ///   <para>Controls whether instancing is enabled.</para>
    /// </summary>
    public bool enableInstancing
    {
      get => (this.m_Flags & DrawRendererFlags.EnableInstancing) != 0;
      set
      {
        if (value)
          this.m_Flags |= DrawRendererFlags.EnableInstancing;
        else
          this.m_Flags &= ~DrawRendererFlags.EnableInstancing;
      }
    }

    /// <summary>
    ///   <para>Sets the Material to use for all drawers that would render in this group.</para>
    /// </summary>
    public Material overrideMaterial
    {
      get
      {
        return this.m_OverrideMaterialInstanceId != 0 ? UnityEngine.Object.FindObjectFromInstanceID(this.m_OverrideMaterialInstanceId) as Material : (Material) null;
      }
      set => this.m_OverrideMaterialInstanceId = value != null ? value.GetInstanceID() : 0;
    }

    /// <summary>
    ///   <para>Selects which pass of the override material to use.</para>
    /// </summary>
    public int overrideMaterialPassIndex
    {
      get => this.m_OverrideMaterialPassIndex;
      set => this.m_OverrideMaterialPassIndex = value;
    }

    /// <summary>
    ///   <para>Sets the Material to use for any drawers in this group that don't meet the requirements.</para>
    /// </summary>
    public Material fallbackMaterial
    {
      get
      {
        return this.m_fallbackMaterialInstanceId != 0 ? UnityEngine.Object.FindObjectFromInstanceID(this.m_fallbackMaterialInstanceId) as Material : (Material) null;
      }
      set => this.m_fallbackMaterialInstanceId = value != null ? value.GetInstanceID() : 0;
    }

    /// <summary>
    ///   <para>Configures what light should be used as main light.</para>
    /// </summary>
    public int mainLightIndex
    {
      get => this.m_MainLightIndex;
      set => this.m_MainLightIndex = value;
    }

    /// <summary>
    ///   <para>Get the name of the shader pass.</para>
    /// </summary>
    /// <param name="index">Index of the shader pass to use.</param>
    public unsafe ShaderTagId GetShaderPassName(int index)
    {
      if (index >= DrawingSettings.maxShaderPasses || index < 0)
        throw new ArgumentOutOfRangeException(nameof (index), string.Format("Index should range from 0 to DrawSettings.maxShaderPasses ({0}), was {1}", (object) DrawingSettings.maxShaderPasses, (object) index));
      fixed (int* numPtr = this.shaderPassNames)
        return new ShaderTagId() { id = numPtr[index] };
    }

    /// <summary>
    ///   <para>Set the name of the shader pass.</para>
    /// </summary>
    /// <param name="index">Index of the shader pass to use.</param>
    /// <param name="shaderPassName">Name of the shader pass.</param>
    public unsafe void SetShaderPassName(int index, ShaderTagId shaderPassName)
    {
      if (index >= DrawingSettings.maxShaderPasses || index < 0)
        throw new ArgumentOutOfRangeException(nameof (index), string.Format("Index should range from 0 to DrawSettings.maxShaderPasses ({0}), was {1}", (object) DrawingSettings.maxShaderPasses, (object) index));
      fixed (int* numPtr = this.shaderPassNames)
        numPtr[index] = shaderPassName.id;
    }

    public bool Equals(DrawingSettings other)
    {
      for (int index = 0; index < DrawingSettings.maxShaderPasses; ++index)
      {
        if (!this.GetShaderPassName(index).Equals(other.GetShaderPassName(index)))
          return false;
      }
      return this.m_SortingSettings.Equals(other.m_SortingSettings) && this.m_PerObjectData == other.m_PerObjectData && this.m_Flags == other.m_Flags && this.m_OverrideMaterialInstanceId == other.m_OverrideMaterialInstanceId && this.m_OverrideMaterialPassIndex == other.m_OverrideMaterialPassIndex && this.m_fallbackMaterialInstanceId == other.m_fallbackMaterialInstanceId && this.m_UseSrpBatcher == other.m_UseSrpBatcher;
    }

    public override bool Equals(object obj)
    {
      return obj != null && obj is DrawingSettings other && this.Equals(other);
    }

    public override int GetHashCode()
    {
      return ((((int) ((DrawRendererFlags) ((int) ((PerObjectData) (this.m_SortingSettings.GetHashCode() * 397) ^ this.m_PerObjectData) * 397) ^ this.m_Flags) * 397 ^ this.m_OverrideMaterialInstanceId) * 397 ^ this.m_OverrideMaterialPassIndex) * 397 ^ this.m_fallbackMaterialInstanceId) * 397 ^ this.m_UseSrpBatcher;
    }

    public static bool operator ==(DrawingSettings left, DrawingSettings right)
    {
      return left.Equals(right);
    }

    public static bool operator !=(DrawingSettings left, DrawingSettings right)
    {
      return !left.Equals(right);
    }
  }
}
